--[[
    表格行
]]--

TableLine = {

}


function TableLine:setTableLineHeaders(headers)
    self._headers = headers
    self._tableLineElement = {}

    local no = Node.TableElement({name = "编号", width = 100, editable = false, dataType = DataType.Number}):addTo(self)
    table.insert(self._tableLineElement, no)
    for i = 1, #headers do
        local header = headers[i]
        local element = Node.TableElement(header):addTo(self.tableLineContent)
        table.insert(self._tableLineElement, element)
    end
end
function TableLine:setUIData(data, idx)
    self.tableLineData = data
    self.tableLineIdx = idx
    self._tableLineElement[1]:setUIData(idx)
    for i = 1, #self._headers do
        self._tableLineElement[i + 1]:setUIData(data[i])
    end
end

function TableLine:ctor()
end

function Node.TableLine(headers)
    local line = Node.Scale9("roundedBox48")
    line.name = "TableLine"
    line:addComponent(HoverArea)
    line:addComponent(SwitchButton)
    line:addComponent(TableLine)
    -- line:addComponent(Layout)

    local content = Node.Layout():addTo(line)
    content.name = "tableLineContent"
    content.layoutType = LayoutType.Horizontal
    content.childAlignY = LayoutChildAlign.Center
    content.leftPadding = 5
    content.rightPadding = 5
    content:addComponent(Stretch)
    line.tableLineContent = content

    line:addComponent(Stretch)
    line.stretchType = StretchType.Horizontal
    line:setTableLineHeaders(headers)

    local border = Node.Scale9("roundedBorder48"):addTo(line)
    border.name = "buttonBorder"
    border:addComponent(Stretch)
    border.interactable = false
    border.styleTarget = line
    border.style = Styles.buttonLabel
    border:addComponent(Align)
    line.border = border
    return line
end